home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Sources / UPrintHandler.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  19.7 KB  |  614 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UPrintHandler.cp
  3. // Copyright © 1985-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UPRINTHANDLER__
  7. #include "UPrintHandler.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __UFAILURE__
  13. #include "UFailure.h"
  14. #endif
  15.  
  16. #ifndef __UGEOMETRY__
  17. #include "UGeometry.h"
  18. #endif
  19.  
  20. #ifndef __UMACAPPGLOBALS__
  21. #include "UMacAppGlobals.h"
  22. #endif
  23.  
  24. #ifndef __UMACAPPUTILITIES__
  25. #include "UMacAppUtilities.h"
  26. #endif
  27.  
  28. #ifndef __UPATCH__
  29. #include "UPatch.h"
  30. #endif
  31.  
  32. #ifndef __UVIEW__
  33. #include "UView.h"
  34. #endif
  35.  
  36. #ifndef __UWINDOW__
  37. #include "UWindow.h"
  38. #endif
  39.  
  40. // Toolbox
  41.  
  42. #ifndef __BALLOONS__
  43. #include <Balloons.h>
  44. #endif
  45.  
  46. #ifndef __DIALOGS__
  47. #include <Dialogs.h>
  48. #endif
  49.  
  50. #ifndef __ERRORS__
  51. #include <Errors.h>
  52. #endif
  53.  
  54. #ifndef __TOOLUTILS__
  55. #include <ToolUtils.h>
  56. #endif
  57.  
  58. // ANSI
  59.  
  60. #ifndef __STDIO__
  61. #include <stdio.h>
  62. #endif
  63.  
  64. //========================================================================================
  65. // static data members
  66. //========================================================================================
  67. Boolean TPrintHandler::gFinderPrintingProceed;                        // proceed with Finder printing
  68. Boolean TPrintHandler::gCouldPrint;
  69. VPoint TPrintHandler::gPageOffset;
  70. TPrintHandler* TPrintHandler::gNullPrintHandler;
  71. TPrintHandler* TPrintHandler::gPrintHandler;
  72. TPrintHandler* TPrintHandler::gCurrPrintHandler;
  73.  
  74.  
  75. //========================================================================================
  76. // CLASS TPrintMenuBehavior
  77. //========================================================================================
  78. #undef Inherited
  79. #define Inherited TBehavior
  80.  
  81. #pragma segment PrintOpen
  82. MA_DEFINE_CLASS_M1(TPrintMenuBehavior, Inherited);
  83.  
  84. //----------------------------------------------------------------------------------------
  85. // TPrintMenuBehavior constructor
  86. //----------------------------------------------------------------------------------------
  87. #pragma segment PrintOpen
  88.  
  89. TPrintMenuBehavior::TPrintMenuBehavior()
  90. {
  91.     fPrintHandler = NULL;
  92. } // TPrintMenuBehavior::TPrintMenuBehavior
  93.  
  94. //----------------------------------------------------------------------------------------
  95. // TPrintMenuBehavior destructor
  96. //----------------------------------------------------------------------------------------
  97. #pragma segment MADestructorRes
  98.  
  99. TPrintMenuBehavior::~TPrintMenuBehavior()
  100. {
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. // TPrintMenuBehavior::IPrintMenuBehavior: 
  105. //----------------------------------------------------------------------------------------
  106. #pragma segment PrintOpen
  107.  
  108. void TPrintMenuBehavior::IPrintMenuBehavior(TPrintHandler*    itsPrintHandler)
  109. {
  110.     this->IBehavior(kPrintMenuBehaviorID);
  111.  
  112.     itsPrintHandler->SetManager(this);
  113.     fPrintHandler = itsPrintHandler;
  114. } // TPrintMenuBehavior::IPrintMenuBehavior 
  115.  
  116. //----------------------------------------------------------------------------------------
  117. // TPrintMenuBehavior::DoScriptCommand: 
  118. //----------------------------------------------------------------------------------------
  119. #pragma segment PrintRes
  120.  
  121. Boolean TPrintMenuBehavior::DoScriptCommand(CommandNumber     aCommandNumber,    
  122.                                             TAppleEvent*    messageEvent,
  123.                                             TAppleEvent*    replyEvent)
  124. {
  125.     Boolean wasHandled = FALSE;
  126.  
  127.     if (fPrintHandler)
  128.     {
  129.         wasHandled = fPrintHandler->DoScriptCommand(aCommandNumber, messageEvent, replyEvent);
  130.         // Note: DoScriptCommand is implemented in TStdPrintHandler, not TPrintHandler. 
  131.     }
  132.  
  133.     if (!wasHandled)
  134.         wasHandled = Inherited::DoScriptCommand(aCommandNumber, messageEvent, replyEvent);
  135.  
  136.     return wasHandled;
  137. } // TPrintMenuBehavior::DoScriptCommand
  138.  
  139. //----------------------------------------------------------------------------------------
  140. // TPrintMenuBehavior::DoMenuCommand: 
  141. //----------------------------------------------------------------------------------------
  142. #pragma segment PrintRes
  143.  
  144. void TPrintMenuBehavior::DoMenuCommand(CommandNumber aCommandNumber)
  145. {
  146.     // Can print if:
  147.     //  • have a print handler, and
  148.     //  • print handler has a view, and
  149.     //    either • view is not shown (e.g., Finder printing), or
  150.     //           • view is active.
  151.     //             • we are printing from the finder
  152.     // NOTE: we don't support printing of view's that are shown, but not active.
  153.  
  154.     // This algorithm allows a document to arbitrate between its various
  155.     // TPrintMenuBehavior objects, representing several printable views owned by the
  156.     // document. This arbitration wasn't supported in MacApp prior to version 3.0.
  157.  
  158.     if (fPrintHandler && fPrintHandler->fView && (!fPrintHandler->fView->IsShown() || fPrintHandler->fView->IsActive() || TPrintHandler::gFinderPrintingProceed))
  159.     {
  160.         if (!fPrintHandler->DoPrintCommand(aCommandNumber))        // if we didn't print, call Inherited
  161.             Inherited::DoMenuCommand(aCommandNumber);
  162.     }
  163.     else
  164.         Inherited::DoMenuCommand(aCommandNumber);
  165. } // TPrintMenuBehavior::DoMenuCommand 
  166.  
  167. //----------------------------------------------------------------------------------------
  168. // TPrintMenuBehavior::DoSetupMenus: 
  169. //----------------------------------------------------------------------------------------
  170. #pragma segment PrintRes
  171.  
  172. void TPrintMenuBehavior::DoSetupMenus()
  173. {
  174.     Inherited::DoSetupMenus();
  175.  
  176.     // see note in TPrintMenuBehavior::DoMenuCommand
  177.     if (fPrintHandler && fPrintHandler->fView && fPrintHandler->fView->IsActive())
  178.         fPrintHandler->DoSetupPrintMenus();
  179. } // TPrintMenuBehavior::DoSetupMenus 
  180.  
  181.  
  182. //========================================================================================
  183. // CLASS TPrintHandler
  184. //========================================================================================
  185. #undef Inherited
  186. #define Inherited TBehavior
  187.  
  188. #pragma segment PrintOpen
  189. MA_DEFINE_CLASS_M1(TPrintHandler, Inherited);
  190.  
  191. //----------------------------------------------------------------------------------------
  192. // TPrintHandler constructor
  193. //----------------------------------------------------------------------------------------
  194. #pragma segment PrintOpen
  195.  
  196. TPrintHandler::TPrintHandler()
  197. {
  198.     fView = NULL;
  199.     fDocument = NULL;
  200.     fManager = NULL;
  201.     fFocusedPage = 1;
  202.     fShowBreaks = FALSE;
  203.  
  204.     fViewPerPage = gZeroVPt;
  205.     fDeviceRes = CPoint(72, 72); // default matches QD default
  206. } // TPrintHandler::TPrintHandler
  207.  
  208. //----------------------------------------------------------------------------------------
  209. // TPrintHandler destructor
  210. //----------------------------------------------------------------------------------------
  211. #pragma segment MADestructorRes
  212.  
  213. TPrintHandler::~TPrintHandler()
  214. {
  215. }
  216.  
  217. //----------------------------------------------------------------------------------------
  218. // TPrintHandler::IPrintHandler: 
  219. //----------------------------------------------------------------------------------------
  220. #pragma segment PrintOpen
  221.  
  222. void TPrintHandler::IPrintHandler(TView* itsView)
  223. {
  224.     this->IBehavior(kPrintBehaviorID);        // attaching to the view is handled by
  225.                                             // AttachPrintHandler
  226.     fView = itsView;
  227. } // TPrintHandler::IPrintHandler 
  228.  
  229. //----------------------------------------------------------------------------------------
  230. // TPrintHandler::GetViewPerPage: 
  231. //----------------------------------------------------------------------------------------
  232. #pragma segment PrintRes
  233.  
  234. VPoint TPrintHandler::GetViewPerPage()
  235. {
  236.     return fViewPerPage;
  237. } // TPrintHandler::GetViewPerPage 
  238.  
  239. //----------------------------------------------------------------------------------------
  240. // TPrintHandler::GetDeviceRes: 
  241. //----------------------------------------------------------------------------------------
  242. #pragma segment PrintRes
  243.  
  244. CPoint TPrintHandler::GetDeviceRes()
  245. {
  246.     return fDeviceRes;
  247. } // TPrintHandler::GetDeviceRes 
  248.  
  249. //----------------------------------------------------------------------------------------
  250. // TPrintHandler::BreakFollowing: 
  251. //----------------------------------------------------------------------------------------
  252. #pragma segment MANever
  253.  
  254. VCoordinate TPrintHandler::BreakFollowing(VHSelect/* vhs */,
  255.                                                  VCoordinate/* previousBreak */,
  256.                                                  Boolean&/* automatic */ )
  257.  
  258. {
  259. #if qDebug
  260.     ProgramBreak("BreakFollowing called for non-subclassed Printhandler");
  261. #endif
  262.  
  263.     return 0;
  264. } // TPrintHandler::BreakFollowing 
  265.  
  266. //----------------------------------------------------------------------------------------
  267. // TPrintHandler::CalcPageStrips: 
  268. //----------------------------------------------------------------------------------------
  269. #pragma segment MANever
  270.  
  271. VPoint TPrintHandler::CalcPageStrips()
  272. {
  273. #if qDebug
  274.     ProgramBreak("CalcPageStrips called for non-subclassed Printhandler");
  275. #endif
  276.     return gZeroVPt;
  277. } // TPrintHandler::CalcPageStrips 
  278.  
  279. //----------------------------------------------------------------------------------------
  280. // TPrintHandler::CalcViewPerPage: 
  281. //----------------------------------------------------------------------------------------
  282. #pragma segment MANever
  283.  
  284. VPoint TPrintHandler::CalcViewPerPage()
  285. {
  286. #if qDebug
  287.     ProgramBreak("CalcViewPerPage called for non-subclassed Printhandler");
  288. #endif
  289.     return gZeroVPt;
  290. } // TPrintHandler::CalcViewPerPage 
  291.  
  292. //----------------------------------------------------------------------------------------
  293. // TPrintHandler::Invalidate:
  294. //----------------------------------------------------------------------------------------
  295. #pragma segment MANonRes
  296.  
  297. void TPrintHandler::Invalidate()
  298. {
  299. }
  300.  
  301. //----------------------------------------------------------------------------------------
  302. // TPrintHandler::Validate: 
  303. //----------------------------------------------------------------------------------------
  304. #pragma segment MANonRes
  305.  
  306. void TPrintHandler::Update()
  307. {
  308. }
  309.  
  310. //----------------------------------------------------------------------------------------
  311. // TPrintHandler::DrawPrintFeedback: 
  312. //----------------------------------------------------------------------------------------
  313. #pragma segment MAPrintingRes
  314.  
  315. //Draw page-breaks, page-numbers, etc.
  316. void TPrintHandler::DrawPrintFeedback(const VRect& /* area */)
  317. {
  318. } // TPrintHandler::DrawPrintFeedback 
  319.  
  320. //----------------------------------------------------------------------------------------
  321. // TPrintHandler::DrawPageBreak: 
  322. //----------------------------------------------------------------------------------------
  323. #pragma segment MAPrintingRes
  324.  
  325. void TPrintHandler::DrawPageBreak(VHSelect /* vhs */,
  326.                                          long /* whichBreak */,
  327.                                          VCoordinate /* loc */,
  328.                                          Boolean /* automatic */)
  329. {
  330. } // TPrintHandler::DrawPageBreak 
  331.  
  332. //----------------------------------------------------------------------------------------
  333. // TPrintHandler::Focus: 
  334. //----------------------------------------------------------------------------------------
  335. #pragma segment MAPrintingRes
  336.  
  337. Boolean TPrintHandler::Focus()
  338. {
  339.     return FALSE;
  340. } // TPrintHandler::Focus 
  341.  
  342. //----------------------------------------------------------------------------------------
  343. // TPrintHandler::FocusOnInterior: 
  344. //----------------------------------------------------------------------------------------
  345. #pragma segment MAPrintingRes
  346.  
  347. void TPrintHandler::FocusOnInterior()
  348. {
  349. } // TPrintHandler::FocusOnInterior 
  350.  
  351. //----------------------------------------------------------------------------------------
  352. // TPrintHandler::GetQDOrigin: 
  353. //----------------------------------------------------------------------------------------
  354. #pragma segment MAPrintingRes
  355.  
  356. CPoint TPrintHandler::GetQDOrigin()
  357. {
  358.     return gZeroPt;
  359. } // TPrintHandler::GetQDOrigin 
  360.  
  361. //----------------------------------------------------------------------------------------
  362. // TPrintHandler::GetViewToQDOffset: 
  363. //----------------------------------------------------------------------------------------
  364. #pragma segment MAPrintingRes
  365.  
  366. VPoint TPrintHandler::GetViewToQDOffset()
  367. {
  368.     return gZeroVPt;
  369. } // TPrintHandler::GetViewToQDOffset 
  370.  
  371. //----------------------------------------------------------------------------------------
  372. // TPrintHandler::GetPrintInfo: 
  373. //----------------------------------------------------------------------------------------
  374. #pragma segment MAPrintingRes
  375.  
  376. TPrintInfo* TPrintHandler::GetPrintInfo()
  377. {
  378.     return NULL;
  379. } // TPrintHandler::GetPrintInfo 
  380.  
  381. //----------------------------------------------------------------------------------------
  382. // TPrintHandler::LocatePageInterior: 
  383. //----------------------------------------------------------------------------------------
  384. #pragma segment MANever
  385.  
  386. VPoint TPrintHandler::LocatePageInterior(long /* pageNumber */)
  387. {
  388.     return gZeroVPt;
  389. } // TPrintHandler::LocatePageInterior 
  390.  
  391. //----------------------------------------------------------------------------------------
  392. // TPrintHandler::MaxPageNumber: 
  393. //----------------------------------------------------------------------------------------
  394. #pragma segment MANever
  395.  
  396. long TPrintHandler::MaxPageNumber()
  397. {
  398.     return 0;
  399. } // TPrintHandler::MaxPageNumber 
  400.  
  401. //----------------------------------------------------------------------------------------
  402. // TPrintHandler::Print: 
  403. //----------------------------------------------------------------------------------------
  404. #pragma segment MAPrint
  405.  
  406. Boolean TPrintHandler::Print(CommandNumber /* itsCommandNumber */)
  407. {
  408.     return TRUE;
  409. } // TPrintHandler::Print 
  410.  
  411. //----------------------------------------------------------------------------------------
  412. // TPrintHandler::PrinterChanged: 
  413. //----------------------------------------------------------------------------------------
  414. #pragma segment MANonRes
  415.  
  416. void TPrintHandler::PrinterChanged()
  417.  
  418. {
  419. } // TPrintHandler::PrinterChanged 
  420.  
  421. //----------------------------------------------------------------------------------------
  422. // TPrintHandler::SetupForFinder: 
  423. //----------------------------------------------------------------------------------------
  424. #pragma segment MAFinder
  425.  
  426. Boolean TPrintHandler::SetupForFinder(CommandNumber /* aCommandNumber */)
  427. {
  428. #if qDebugMsg
  429.     fprintf(stderr, "SetupForFinder called for a view that can't\n");
  430. #endif
  431.  
  432.     return FALSE;
  433. } // TPrintHandler::SetupForFinder 
  434.  
  435. //----------------------------------------------------------------------------------------
  436. // TPrintHandler::RedoPageBreaks: 
  437. //----------------------------------------------------------------------------------------
  438. #pragma segment MANever
  439.  
  440. void TPrintHandler::RedoPageBreaks()
  441. {
  442. } // TPrintHandler::RedoPageBreaks 
  443.  
  444. //----------------------------------------------------------------------------------------
  445. // TPrintHandler::Reset: 
  446. //----------------------------------------------------------------------------------------
  447. #pragma segment MANever
  448.  
  449. void TPrintHandler::Reset()
  450. {
  451. } // TPrintHandler::Reset 
  452.  
  453. //----------------------------------------------------------------------------------------
  454. // TPrintHandler::DoPrintCommand: 
  455. //----------------------------------------------------------------------------------------
  456. #pragma segment MANever
  457.  
  458. Boolean TPrintHandler::DoPrintCommand(CommandNumber /* aCommandNumber */)
  459. {
  460.     return FALSE;
  461. } // TPrintHandler::DoPrintCommand 
  462.  
  463. //----------------------------------------------------------------------------------------
  464. // TPrintHandler::DoSetupPrintMenus: 
  465. //----------------------------------------------------------------------------------------
  466. #pragma segment MANever
  467.  
  468. void TPrintHandler::DoSetupPrintMenus()
  469. {
  470. } // TPrintHandler::DoSetupPrintMenus 
  471.  
  472. //----------------------------------------------------------------------------------------
  473. // TPrintHandler::SetDefaultPrintInfo: 
  474. //----------------------------------------------------------------------------------------
  475. #pragma segment PrintOpen
  476.  
  477. // Meant to be overridden in a subclass that really prints 
  478. void TPrintHandler::SetDefaultPrintInfo()
  479. {
  480. } // TPrintHandler::SetDefaultPrintInfo 
  481.  
  482. //----------------------------------------------------------------------------------------
  483. // TPrintHandler::SetPageInterior: 
  484. //----------------------------------------------------------------------------------------
  485. #pragma segment MANever
  486.  
  487. void TPrintHandler::SetPageInterior(long /* pageNumber */)
  488. {
  489. } // TPrintHandler::SetPageInterior 
  490.  
  491. //----------------------------------------------------------------------------------------
  492. // TPrintHandler::SetPageOffset: 
  493. //----------------------------------------------------------------------------------------
  494. #pragma segment MANever
  495.  
  496. void TPrintHandler::SetPageOffset(const VPoint& /* coord */)
  497. {
  498. } // TPrintHandler::SetPageOffset 
  499.  
  500.  
  501. //----------------------------------------------------------------------------------------
  502. // TPrintHandler::GetManager: 
  503. //----------------------------------------------------------------------------------------
  504. #pragma segment PrintOpen
  505.  
  506. TPrintMenuBehavior* TPrintHandler::GetManager()
  507. {
  508.     return fManager;
  509. } // TPrintHandler::GetManager 
  510.  
  511. //----------------------------------------------------------------------------------------
  512. // TPrintHandler::SetManager: 
  513. //----------------------------------------------------------------------------------------
  514. #pragma segment PrintOpen
  515.  
  516. void TPrintHandler::SetManager(TPrintMenuBehavior* itsManager)
  517. {
  518.     fManager = itsManager;
  519. } // TPrintHandler::SetManager 
  520.  
  521. //----------------------------------------------------------------------------------------
  522. // TPrintHandler::SetOwner
  523. //----------------------------------------------------------------------------------------
  524. #pragma segment MAOpen
  525.  
  526. void TPrintHandler::SetOwner(TEventHandler* itsOwner) // override
  527. {
  528.     Inherited::SetOwner(itsOwner);
  529.  
  530.     if (fView)
  531.     {
  532.         TWindow* window = fView->GetWindow();
  533.         if (window)
  534.         {
  535.             if (itsOwner)
  536.             {
  537.                 if (itsOwner == fView)
  538.                     window->SetScriptingPrintHandler(this);
  539. #if qDebug
  540.                 else
  541.                     ProgramBreak("Print handler owner != fView");
  542. #endif
  543.             }
  544.             else
  545.             {
  546.                 window->ReleaseScriptingPrintHandler(this);
  547.                 // Note: This does not get called when a window is closed
  548.                 // because the window goes away first. 
  549.             }
  550.         }
  551.     }
  552. } // TPrintHandler::SetOwner
  553.  
  554. //----------------------------------------------------------------------------------------
  555. // TPrintHandler::TerminateUPrinting: 
  556. //----------------------------------------------------------------------------------------
  557. #pragma segment PrintRes
  558. void TPrintHandler::TerminateUPrinting()
  559. {
  560.     // Thank you
  561. }
  562.  
  563. //----------------------------------------------------------------------------------------
  564. // TPrintHandler::PrepareForFinderPrinting: 
  565. //----------------------------------------------------------------------------------------
  566. #pragma segment PrintRes
  567. void TPrintHandler::PrepareForFinderPrinting(const FSSpec* /* targetPrinter */)
  568. {
  569.     // Thank you
  570. }
  571.  
  572. //----------------------------------------------------------------------------------------
  573. // TPrintHandler::DispatcherIsAvailable: 
  574. //----------------------------------------------------------------------------------------
  575. #pragma segment PrintRes
  576. void TPrintHandler::DispatcherIsAvailable()
  577. {
  578.     // Thank you
  579. }
  580.  
  581. //----------------------------------------------------------------------------------------
  582. // TPrintHandler::GetSavePrintInfoSize: 
  583. //----------------------------------------------------------------------------------------
  584. #pragma segment PrintRes
  585. long TPrintHandler::GetSavePrintInfoSize(TPrintInfo* /* itsPrintInfo */, TFile* /* itsFile */, Boolean /* useRsrcFork */)
  586. {
  587.     // Thank you
  588.     return 0;
  589. }
  590.  
  591. //----------------------------------------------------------------------------------------
  592. // TPrintHandler::SavePrintInfo: 
  593. //----------------------------------------------------------------------------------------
  594. #pragma segment PrintRes
  595. void TPrintHandler::SavePrintInfo(TPrintInfo* /* itsPrintInfo */, TFile* /* itsFile */, Boolean /* useRsrcFork */)
  596. {
  597.     // Thank you
  598. }
  599.  
  600. //----------------------------------------------------------------------------------------
  601. // TPrintHandler::RestorePrintInfo: 
  602. //----------------------------------------------------------------------------------------
  603. #pragma segment PrintRes
  604. TPrintInfo* TPrintHandler::RestorePrintInfo(TFile* /* itsFile */, Boolean /* useRsrcFork */)
  605. {
  606.     // Thank you
  607.     return NULL;
  608. }
  609.  
  610. //----------------------------------------------------------------------------------------
  611. // End of UPrintHandler.cp
  612.  
  613. #pragma segment Inline
  614.